package com.hotel.servlet;

import com.hotel.bean.Hotel;
import com.hotel.dao.HotelDao;
import com.hotel.util.DBOperation;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author KungSu.
 * @create 2021-05-12 9:58
 */
@WebServlet(value = "/OrderHotelServlet")
public class OrderHotelServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        //操作数据库
        SqlSession sqlSession = DBOperation.getSqlSession();
        //新建实体类
        HotelDao hotelDao= sqlSession.getMapper(HotelDao.class);
        Hotel hotel;
        switch (id){
            case "1":
                hotel=hotelDao.findHotleById(1);
                System.out.println(hotel);
                request.setAttribute("hotel",hotel);
                request.getRequestDispatcher("/jsp/orderbocuiHotel.jsp").forward(request,response);
                sqlSession.close();
                break;
            case "2":
                hotel=hotelDao.findHotleById(2);
                System.out.println(hotel);
                request.setAttribute("hotel",hotel);
                request.getRequestDispatcher("/jsp/orderjianguoHotel.jsp").forward(request,response);
                sqlSession.close();
                break;
            case "3":
                hotel=hotelDao.findHotleById(3);
                System.out.println(hotel);
                request.setAttribute("hotel",hotel);
                request.getRequestDispatcher("/jsp/ordernanyuanHotel.jsp").forward(request,response);
                sqlSession.close();
                break;
            case "4":
                hotel= hotelDao.findHotleById(4);
                System.out.println(hotel);
                request.setAttribute("hotel",hotel);
                request.getRequestDispatcher("/jsp/orderjinglunHotel.jsp").forward(request,response);
                sqlSession.close();
                break;
        }
    }
}
